package com.cai.servlet.common.user;

import com.cai.dao.UserDao;
import com.cai.dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author RuoLi
 */
@WebServlet(name = "ServletUserAccountStatus", value = "/common/userAccountStatus")
public class ServletUserAccountStatus extends HttpServlet {
    UserDao userDao = new UserDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //冻结
        getData(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

    private void getData(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String userAccount = req.getParameter("userAccount");
        String userStatus = req.getParameter("userStatus");
        int status = userDao.setAccountStatus(userStatus, userAccount);
        if (status!=0){
            //操作成功
            resp.getWriter().println(1);
        }else {
            resp.getWriter().println(0);
        }
    }
}
